class CommandHistory:
    """
    命令历史类，维护一个命令的历史队列。
    """
    def __init__(self):
        self.history = []
        self.backup = []

    def add(self, command):
        self.history.append(command)

    def undo(self):
        if self.history:
            actor = self.history.pop()
            self.backup.append(actor)
            return actor
        return None
    
    def redo(self):
        if self.backup:
            actor = self.backup.pop()
            self.history.append(actor)
            return actor
        return None